package homework_java.RoomQ;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
class MyTicket implements Comparable<MyTicket>{
    private int sid;
	private Date date;
    private int seatNo;
    MyTicket(int id){
       this.sid=id;
    }
	public int getSid() {
		return sid;
	}
	public void setSid(int sid) {
		this.sid = sid;
	}
	public Date getDate() {
		return date;
	}
	public void setDate(Date date) {
		this.date = date;
	}
	public int getSeatNo() {
		return seatNo;
	}
	public void setSeatNo(int seatNo) {
		this.seatNo = seatNo;
	}
    //sid不重复
    @Override
    public int hashCode() {
        // TODO Auto-generated method stub
        return new HashCodeBuilder().append(this.sid).toHashCode();
    }
    @Override
    public boolean equals(Object obj) {
       MyTicket ss=(MyTicket)obj;
       return new EqualsBuilder().append(this.sid,ss.sid).isEquals();
    }
    @Override
    public int compareTo(MyTicket o) {
        if(this.getSid()<o.getSid())
            return -1;
        else if(this.getSid()>o.getSid())
            return 1;
        else
            return 0;
    }
}
/*class MyticketComparator implements Comparator<MyTicket> {
    @Override
    public int compare(MyTicket o1, MyTicket o2) {
        return o1.compareTo(o2);
    }
}*/
public class Demo {
    static class Film {
        public static void testPrint(List<MyTicket> tempList) {
            for(MyTicket ticket: tempList) {
                System.out.println("sid: "+ticket.getSid());
            }
        }

        public static void testSort(List<MyTicket> list) {
            Collections.sort(list);
            Film.testPrint(list);
        }

       /* public static void testSortor(List<MyTicket> list) {
            Collections.sort(list, new MyticketComparator());
            Film.testPrint(list);
        }*/

        public static void doAll(HashSet<MyTicket> hashSet) {
            List<MyTicket> tempList = new ArrayList<MyTicket>(hashSet);
            Film.testPrint(tempList);
            System.out.println("排序后:");
            Film.testSort(tempList);
            //System.out.println("sort2:");
            //Film.testSortor(tempList);
        }
    }

    public static void main(String[] args){
        String name="计算机1804班";
        System.out.println(name);
        HashSet<MyTicket> hashSet=new HashSet<MyTicket>();
        hashSet.add(new MyTicket(81));
        hashSet.add(new MyTicket(88));
        hashSet.add(new MyTicket(89));
        hashSet.add(new MyTicket(82));
        hashSet.add(new MyTicket(2));
        hashSet.add(new MyTicket(90));
        hashSet.add(new MyTicket(-98));
        hashSet.add(new MyTicket(44));
        Film.doAll(hashSet);
    }
}

    

